<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>01-02/实现一个盒子的水平居中</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .box1 {
            position: relative;
            width: 800px;
            height: 500px;
            border: 1px solid #000;
            margin: 20px auto;
        }
        .box2 {
            position: absolute;
            left: 50%;
            top: 0;
            width: 200px;
            height: 200px;
            margin-left: -100px;
            background-color: pink;
        }
        .box3 {
            position: absolute;
            left: 50%;
            bottom: 0;
            width: 200px;
            height: 200px;
            transform: translate(-50%);
            background-color: burlywood;
        }
        .box1 p {
            font: 16px/200px "微软雅黑";
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="box1">
        <div class="box2">
            <p>居中方法1</p>           
        </div>
        <div class="box3">
            <p>居中方法2</p>
        </div>
    </div>
</body>
</html>